const state = {
    userInfo: localStorage.getItem('userInfo') ? JSON.parse(localStorage.getItem('userInfo')) : {},
    token: localStorage.getItem('token') ? JSON.parse(localStorage.getItem('token')) : '', // 当前登录的token
    refer: localStorage.getItem('refer') ? JSON.parse(localStorage.getItem('refer')) : {},
    share: localStorage.getItem('share') ? JSON.parse(localStorage.getItem('share')) : false,
    tokenArray: localStorage.getItem('tokenArray') ? JSON.parse(localStorage.getItem('tokenArray')) : [], // 本地token集合
    brandArray: localStorage.getItem('brandArray') ? JSON.parse(localStorage.getItem('brandArray')) : [], // 品牌上次进入的系统号
    system: localStorage.getItem('system') ? JSON.parse(localStorage.getItem('system')) : '',
    phoneType: localStorage.getItem('phoneType') ? JSON.parse(localStorage.getItem('phoneType')) : '',
    phone: sessionStorage.getItem('phone') ? JSON.parse(sessionStorage.getItem('phone')) : '',
    systemData: sessionStorage.getItem('systemData') ? JSON.parse(sessionStorage.getItem('systemData')) : {},// 系统信息
    certification: localStorage.getItem('certification') ? JSON.parse(localStorage.getItem('certification')) : 'newPassword', // 实名认证
    stateQwk: localStorage.getItem('stateQwk') ? JSON.parse(localStorage.getItem('stateQwk')) : true, // token过期后防止多次发请求形成死循环
    tokenType: 2, // 1正式 2 临时
    frontBrand: [], // 首页店主推荐品牌
    bindWxInfo: sessionStorage.getItem('bindWxInfo') ? JSON.parse(sessionStorage.getItem('bindWxInfo')) : {},
    platform:""//是否是flutter
};
const getters = {
    certification: (state) => state.certification,
    userInfo: state => state.userInfo,
    token: state => state.token,// 当前登录的token
    tokenArray: state => state.tokenArray, // token集合
    brandArray: state => state.brandArray, // 上次进入系统号集合
    system: state => state.system, //系统号
    phoneType: state => state.phoneType, //手机号计算出的类型登录注册还是找回
    phone: state => state.phone, //手机号
    stateQwk: state => state.stateQwk, //token过期后防止多次发请求形成死循环
    systemData(state, getters) { //系统名称图
        return state.systemData;
    },
    tokenType: (state) => state.tokenType,
    frontBrand: (state) => state.frontBrand,
    bindWxInfo: (state) => state.bindWxInfo,
};
const actions = {};
const mutations = {
    forCertification(state, type) {
        state.certification = type;
        localStorage.setItem('certification', JSON.stringify(type));
    },
    setStateQwk(state, type) {
        state.stateQwk = type;
        localStorage.setItem('stateQwk', JSON.stringify(type));
    },
    setUserInfo(state, data) {
        // 用户信息
        localStorage.setItem('userInfo', JSON.stringify(data));
        state.userInfo = JSON.parse(localStorage.getItem('userInfo'));
    },
    phone(state, data) {
        //登录弹窗
        sessionStorage.setItem('phone', JSON.stringify(data));
        state.phone = JSON.parse(sessionStorage.getItem('phone'));
    },
    setToken(state, data) {
        // 当前正式token
        localStorage.setItem('token', JSON.stringify(data));
        state.token = JSON.parse(localStorage.getItem('token'));
    },
    refer(state, data) {
        // 推荐人id
        localStorage.setItem('refer', JSON.stringify(data));
        state.refer = JSON.parse(localStorage.getItem('refer'));
    },
    share(state, data) {
        localStorage.setItem('share', JSON.stringify(data));
        state.share = JSON.parse(localStorage.getItem('share'));
    },
    setSystem(state, data) {
        //系统号
        localStorage.setItem('system', JSON.stringify(data || ""));
        state.system = JSON.parse(localStorage.getItem('system'));
    },
    setTokenArray(state, data) {
        // token集合
        localStorage.setItem('tokenArray', JSON.stringify(data));
        state.tokenArray = JSON.parse(localStorage.getItem('tokenArray'));
    },
    setBrandArray(state, data) {
        // 上次登录系统号集合
        localStorage.setItem('brandArray', JSON.stringify(data));
        state.brandArray = JSON.parse(localStorage.getItem('brandArray'));
    },
    setSystemData(state, data) {
        sessionStorage.setItem('systemData', JSON.stringify(data));
        state.systemData = JSON.parse(sessionStorage.getItem('systemData'));
    },
    setTokenType(state, data) {
        sessionStorage.setItem('tokenType', JSON.stringify(data));
        state.tokenType = JSON.parse(sessionStorage.getItem('tokenType'));
    },
    setFrontBrand(state, data) {
        sessionStorage.setItem('frontBrand', JSON.stringify(data));
        state.frontBrand = JSON.parse(sessionStorage.getItem('frontBrand'));
    },
    setBindWxInfo(state, data) {
        sessionStorage.setItem('bindWxInfo', JSON.stringify(data));
        state.bindWxInfo = JSON.parse(sessionStorage.getItem('bindWxInfo'));
    },
    setPlatform(state, data){
        state.platform = data;
    }
};

export default {
    state,
    getters,
    actions,
    mutations
};
